package com.lsht.web.controller.siwei;

import com.github.pagehelper.PageInfo;
import com.lsht.common.bo.IdListAcceptBo;
import com.lsht.common.core.controller.BaseController;
import com.lsht.common.core.domain.AjaxResult;
import com.lsht.system.domain.siwei.BusHelpFile;
import com.lsht.system.service.BusHelpFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author zyc
 * @date 2023/10/11 14:40
 */
@RestController
@RequestMapping("/siwei/file")
@Api(value = "BusHelpFile", description = "帮助文档", tags = "帮助文档")
public class BusHelpFileController extends BaseController {
    @Autowired
    private BusHelpFileService busHelpFileService;

    /**
     * 新增帮助文档
     */
    @PostMapping(ADD_FUNCTION_URL)
    @ApiOperation(value = ADD_FUNCTION, httpMethod = "POST", response = BusHelpFile.class, tags = "帮助文档")
    public AjaxResult genAdd(BusHelpFile busHelpFile, MultipartFile file) {
        return busHelpFileService.genAdd(busHelpFile,file);
    }

    /**
     * 删除帮助文档
     */
    @PostMapping(DELETE_BY_ID_FUNCTION_URL)
    @ApiOperation(value = DELETE_BY_ID_FUNCTION, httpMethod = "POST", response = AjaxResult.class, tags = "帮助文档")
    public AjaxResult genDeleteById(@RequestBody IdListAcceptBo idListAcceptBo) {
        List<String> idList = idListAcceptBo.getIdList();
        if (CollectionUtils.isNotEmpty(idList)) {
            return toAjax(busHelpFileService.genDeleteById(idList));
        }
        return AjaxResult.error();
    }

    /**
     * 修改帮助文档
     */
    @PostMapping(UPDATE_BY_ID_FUNCTION_URL)
    @ApiOperation(value = UPDATE_BY_ID_FUNCTION, httpMethod = "POST", response = AjaxResult.class, tags = "帮助文档")
    public AjaxResult genUpdateById(@RequestBody BusHelpFile busHelpFile) {
        return toAjax(busHelpFileService.genUpdateById(busHelpFile));
    }

    /**
     * 查询帮助文档列表
     */
    @PostMapping(QUERY_LIST_FUNCTION_URL)
    @ApiOperation(value = QUERY_LIST_FUNCTION, httpMethod = "POST", response = BusHelpFile.class, tags = "帮助文档")
    public AjaxResult genQueryList(@RequestBody BusHelpFile busHelpFile) {
        startPage();
        List<BusHelpFile> list = busHelpFileService.genQueryList(busHelpFile);
        return AjaxResult.success(new PageInfo<>(list));
    }
}
